package com.ksl.kinglockguard.activity;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ksl.kinglockguard.LockApplication;
import com.ksl.kinglockguard.R;
import com.ksl.kinglockguard.activity.base.AbstractActivity;
import com.ksl.kinglockguard.bitmap.ImageLoader;
import com.ksl.kinglockguard.data.Constants;
import com.ksl.kinglockguard.data.SharePreferenceSdkData;
import com.ksl.kinglockguard.data.UserCountHabit;
import com.ksl.kinglockguard.domain.BannerList;
import com.ksl.kinglockguard.domain.BannerNews;
import com.ksl.kinglockguard.domain.MainList;
import com.ksl.kinglockguard.domain.MainNews;
import com.ksl.kinglockguard.network.NetworkTask;
import com.ksl.kinglockguard.utils.ImageUtils;
import com.ksl.kinglockguard.widget.GuideGallery;
import com.ksl.kinglockguard.widget.ScaleImageView;
import com.ksl.kinglockguard.widget.common.CustomProgressDialog;
import com.ksl.kinglockguard.widget.common.LoadFailedView;
import com.ksl.kinglockguard.widget.waterfall.PLA_AbsListView;
import com.ksl.kinglockguard.widget.waterfall.PLA_AbsListView.OnScrollListener;
import com.ksl.kinglockguard.widget.waterfall.PLA_AdapterView;
import com.ksl.kinglockguard.widget.waterfall.PLA_AdapterView.OnItemClickListener;
import com.ksl.kinglockguard.widget.waterfall.XListView;
import com.ksl.kinglockguard.widget.waterfall.XListView.IXListViewListener;
import com.lsk.open.core.MyLog;
import com.lsk.open.core.net.NetConnectTask;
import com.lsk.open.core.net.NetConnectTask.TaskListener;
import com.lsk.open.core.net.NetHeadUtils;
import com.lsk.open.core.serialize_cache.CacheDataManager;

public class LockMainActivity extends AbstractActivity implements IXListViewListener {
    private XListView mAdapterView = null;
    private StaggeredAdapter mAdapter = null;
    private BannerImageAdapter bannerAdapter = null;
    private ImageView mForeBmpIV;
    private ImageView mMainBlurBmpIV;
    private ImageView mBackBmpIV;
    private ImageView h5IconIV;
    private MainList newslist = null;
    private ImageLoader mImageLoader;
    private ScaleAnimation scaleAni;
    private TranslateAnimation transAni;
    private int statusBarHeight;
    private int titleBarHeight;
    private AnimationSet bkAnimSet;
    private AnimationSet foreAnimSet;
    private float itemX;
    private float itemY;
    private AnimationSet shakeAnimSet;
    private Animation shakeAlphaAnim;
    private Animation shakeAnim;
    private int lastItemPosition = -1;
    private Animation itemDownAnim;
    private Animation itemUpAnim;
    private View itemView;
    private View clickedView;
    private int clickedItemPosition;
    private int firstItem;
    private View lockHeaderView;
    private int clickedPosition;
    private CustomProgressDialog mProgressDialog;
    private MainList recommendNews;
    private BannerList bannerNews;
    private float widthScaleFactor;
    private float heightScaleFactor;
    private LoadFailedView view_load_failed;
	private RelativeLayout lay_list_container;
	private LinkedList<MainNews> mInfos;
	private LinkedList<BannerNews> mBannerInfos;
	private Bitmap mainBlurBmp;
	private boolean isBack = false; //是否back键被按下
	private boolean isForwarding = false; //是否正在执行activity跳转
	private boolean isAnimating = false; //是否正在执行动画
	private boolean isRequesting = false;//是否正在请求服务器，防止用户短时间内多次上滑加载，上一次请求完成才执行下一次请求
	private boolean noMoreData = false;
	private TextView bannerNewsTv;
	private static int minID;
	private int articleNumber = 0;
    private LinearLayout settingsView;
    private Bitmap bBmp;
    private GuideGallery imagesGallery;
    private static final Handler handler = new Handler();
    private static final int CLOSE_SCREEN_POP_TIME = 5000;
    private static final int SHOULD_NOT_SHOW = 0;
    private static final int SHOULD_BE_SHOWN = 1;
	
	public static final int ON_LOAD_MORE = 0;//上滑加载更多
	public static final int ON_OPEN_APP = 1;//首次打开app
	public static final int ARTICLE_NUMBER_FIXED = 20;//首页列表每次请求文章数量
	public static final int ARTICLE_MAX_NUMBER = 300;//首页列表请求文章数量上限
	public static final int BACK_FROM_DETAIL_NOANIM = 0;//从详情页面返回，不执行动画
	public static final int BACK_RROM_DETAIL_PAGE = 1;//从详情页面返回，执行动画
	public static final int BACK_RROM_SETTING_PAGE = 2;//从设置页面返回
	public static final int BANNER_IMAGE_LENGTH = 5;//焦点图数量
	
	
	@SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lock_main);
        UserCountHabit.setUserCount(LockMainActivity.this, UserCountHabit.HOME_PAGE);//用户行为统计
        initView();
        initListener();
        initData();
        LockApplication.FLAG_MAIN_OPENED = true;
        handler.postDelayed(closeSysScreen, CLOSE_SCREEN_POP_TIME);//5秒后弹出关闭系统锁屏的提示
     
//        createShortCut();
    }
	
	Runnable closeSysScreen = new Runnable() {
    	
    	@Override
    	public void run() {
    		// TODO Auto-generated method stub
    		MyLog.i("jyh1", "~~~~getFirstLaunched~~~"+SharePreferenceSdkData.getFirstLaunched(getApplicationContext()));
    		if(SharePreferenceSdkData.getFirstLaunched(getApplicationContext())){
            	SharePreferenceSdkData.setFirstLaunched(getApplicationContext(), false);
            	openScreenGuidance();
    		}
    	}
    };
	
	public void openScreenGuidance() {
		Intent intent = new Intent(LockMainActivity.this, GuidanceActivity.class);
		startActivity(intent);
	}
	
	/**
     * 
     * 先加载本地缓存的焦点图广告，后台请求服务器焦点图广告，成功之后替换掉之前的缓存
     * 
     */
    private void getBanner() {
    	if (NetHeadUtils.isNetWorking(getApplicationContext()))
    		RequestBannerList();
    	bannerNews = (BannerList) CacheDataManager.getListCacheOrLoadSeriaByKey(Constants.BANNER_LIST);
    	if(bannerNews != null){
    		mBannerInfos.clear();
    		mBannerInfos.addAll(bannerNews.getNewslist());
    		bannerAdapter.notifyDataSetChanged();
    	}
    }
	
    /**
     * 
     * 读取心跳缓存的数据
     * 
     */
    private void readCacheData() {
		recommendNews = (MainList) CacheDataManager.getListCacheOrLoadSeriaByKey(Constants.FSKEY_NEWlISTS);
		//if (recommendNews != null&&false) {//false to do ydy for refresh just
		if (recommendNews != null) {
			minID = recommendNews.getMinID();
			articleNumber += ARTICLE_NUMBER_FIXED;
			setData();
		}
    }
    
    /**
     * 
     * 请求服务器数据
     * 
     * @type
     * type == ON_OPEN_APP  首次打开app
     * type == ON_LOAD_MORE 上滑加载更多
     * 
     */
    private void requestServerData(int type) {
    	if (NetHeadUtils.isNetWorking(getApplicationContext())) {
			MyLog.i("jyh", "~~~~~~~~~cache is not ok,reuqest server data~~~~~~~~");
			if(type == ON_OPEN_APP){
				mProgressDialog.show();
				RequestRecommendAdList(0,ON_OPEN_APP);
			}else if(type == ON_LOAD_MORE){
				if(!noMoreData){
					if(!isRequesting){
						isRequesting = true;
						if(articleNumber < ARTICLE_MAX_NUMBER)
							RequestRecommendAdList(minID,ON_LOAD_MORE);
						else{
							mAdapterView.stopLoadMore();
							Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.beyond_300_articles), Toast.LENGTH_SHORT).show();
						}
					}
				}else{
					mAdapterView.stopLoadMore();
					Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.no_more_content), Toast.LENGTH_SHORT).show();
				}
			}
		}else{
			MyLog.i("jyh", "~~~~~~~~~no network~~~~~~~~");
			if(type == ON_LOAD_MORE){
				mAdapterView.stopLoadMore();
				Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.network_not_connected), Toast.LENGTH_SHORT).show();
			}else if(type == ON_OPEN_APP){
				lay_list_container.setVisibility(View.GONE);
				view_load_failed.setVisibility(View.VISIBLE);
			}
		}
    }
    
    private void setData(){
        mAdapterView.stopLoadMore();
        mAdapter.addItemLast(recommendNews.getNewslist());
        mAdapter.notifyDataSetChanged();
    }
    
    /**
     * 
     * 请求首页资讯列表
     * @requestType
     * requestType == ON_OPEN_APP  首次打开app
     * requestType == ON_LOAD_MORE 上滑加载更多 
     * 
     */
    private void RequestRecommendAdList(int minid,final int requestType) {
		JSONObject request = new JSONObject();
		try {
			request.put("number", ARTICLE_NUMBER_FIXED);
			request.put("group", SharePreferenceSdkData.getUserGroup(getApplicationContext()));
			request.put("preference", SharePreferenceSdkData.getUserPreference(getApplicationContext()));
//			request.put("cat", Constants.ARTICLE_CAT_NEWS);
			if(requestType == ON_LOAD_MORE && minid !=0)
				request.put("min_id", minid);
			MyLog.i("jyh", "~~~~~~~~MIN id is "+minid);
		} catch (JSONException e1) {
			e1.printStackTrace();
		}
		NetConnectTask netTask = NetworkTask.requestMainPageList(this,request.toString());
		netTask.setListener(new TaskListener() {
			@Override
			public void onNoNetworking() {
				MyLog.i("wmm","onNoNetworking");
				isRequesting = false;
				mProgressDialog.dismiss();
				mAdapterView.stopLoadMore();
				Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.no_network_env) , Toast.LENGTH_SHORT).show();
			}
			@Override
			public void onNetworkingError() {
				MyLog.i("wmm","onNetworkingError");
				isRequesting = false;
				mProgressDialog.dismiss();
				mAdapterView.stopLoadMore();
				Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.network_error_env) , Toast.LENGTH_SHORT).show();
			}
			@Override
			public void onPostExecute(byte[] bytes) {
				MyLog.d("ydy", "requestAdList-----------onPostExecute: "+ new String(bytes));
				try {
					JSONObject result = new JSONObject(new String(bytes));
					String errno = result.getString("errno");
					JSONArray dataList = null;
					if(errno.equals("200")){
						dataList = result.getJSONArray("data");
						newslist = MainList.parse(dataList);
						minID = newslist.getMinID();
						articleNumber += ARTICLE_NUMBER_FIXED;
						 if (!checkDataCache()) {
							CacheDataManager.deleteSeriaFile(Constants.FSKEY_NEWlISTS);
							CacheDataManager.setListCacheAndWriteByKey(Constants.FSKEY_NEWlISTS, newslist);
						 }
						MyLog.i("jyh", "~~~~~~~~articleNumber is "+articleNumber);
					}else{
						Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.network_error_env) , Toast.LENGTH_SHORT).show();
						return;
					}
					if (dataList.length() < ARTICLE_NUMBER_FIXED)
						noMoreData = true;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				recommendNews = newslist;
				isRequesting = false;
				setData();
				mProgressDialog.dismiss();
			}
		});

	}
    
    /**
     * 
     * 请求焦点图广告
     * 
     */
    private void RequestBannerList() {
		JSONObject request = new JSONObject();
		try {
			request.put("number", "5");
		} catch (JSONException e1) {
			e1.printStackTrace();
		}
		NetConnectTask netTask = NetworkTask.requestBanner(this,request.toString());
		netTask.setListener(new TaskListener() {
			@Override
			public void onNoNetworking() {
			}
			@Override
			public void onNetworkingError() {
			}
			@Override
			public void onPostExecute(byte[] bytes) {
				MyLog.d("ydy", "requestBannerList-----------onPostExecute: "+ new String(bytes));
				try {
					JSONObject result = new JSONObject(new String(bytes));
					String errno = result.getString("errno");
					JSONArray dataList = null;
					if(errno.equals("200")){
						dataList = result.getJSONArray("data");
						bannerNews = BannerList.parse(dataList);
					}else{
						Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.network_error_env) , Toast.LENGTH_SHORT).show();
						return;
					}
					if (bannerNews.getBannerCount() >= 5){
						CacheDataManager.deleteSeriaFile(Constants.BANNER_LIST);
						CacheDataManager.setListCacheAndWriteByKey(Constants.BANNER_LIST, bannerNews);
						mBannerInfos.clear();
						mBannerInfos.addAll(bannerNews.getNewslist());
						imagesGallery.setSelection(mBannerInfos.size() * 2000);
						bannerAdapter.notifyDataSetChanged();
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

	}
    
    /**
     * 
     * 首页资讯列表适配器
     * 
     */
    public class StaggeredAdapter extends BaseAdapter {
        private Context mContext;

        public StaggeredAdapter(Context context, XListView xListView) {
            mContext = context;
            mInfos = new LinkedList<MainNews>();
        }

        @SuppressLint("NewApi") @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder;
            MainNews itemNews = mInfos.get(position);

            if (convertView == null) {
                LayoutInflater layoutInflator = LayoutInflater.from(parent.getContext());
                convertView = layoutInflator.inflate(R.layout.lock_infos_list, null);
                holder = new ViewHolder();
                holder.imageView = (ScaleImageView) convertView.findViewById(R.id.news_pic);
                holder.contentView = (TextView) convertView.findViewById(R.id.news_title);
                convertView.setTag(holder);
            }

            holder = (ViewHolder) convertView.getTag(); 
            holder.imageView.setImageWidth(200);
            float ratio = itemNews.getHeight()/(float)itemNews.getWidth();
            holder.imageView.setImageHeight((int)(200*ratio));
            holder.contentView.setText(itemNews.getTitle());
            holder.imageView.setImageResource(R.drawable.zwt_pic);
            mImageLoader.DisplayImage(itemNews.getMiddleImageUrl(), holder.imageView, false,ImageLoader.LOCK_ITEM_PICTURE);
            MyLog.i("wmm", "DisplayImage");
            if(position > lastItemPosition){
            	flipUpAnim(convertView, mContext);
            	lastItemPosition = position;
            }
            return convertView;
        }

        class ViewHolder {
            ScaleImageView imageView;
            TextView contentView;
            TextView timeView;
        }

        @Override
        public int getCount() {
            return mInfos.size();
        }

        @Override
        public Object getItem(int arg0) {
            return mInfos.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            return 0;
        }

        public void addItemLast(List<MainNews> datas) {
        	LinkedList<MainNews> mainInfos = new LinkedList<MainNews>();
        	LinkedList<String> infoId = new LinkedList<String>();
        	//剔除首页列表具有重复id的内容
        	for (MainNews info : datas) {
        		if(!infoId.contains(String.valueOf(info.getId()))){
        			mainInfos.addLast(info);
        			infoId.add(String.valueOf(info.getId()));
        		}
        	}
        	//剔除不需要在首页列表显示的内容（list_show字段为0）
        	for (MainNews info : mainInfos) {
            	if(info.getList_show() != SHOULD_NOT_SHOW)
            		mInfos.addLast(info);
            }
        }

//        public void addItemTop(List<CommonNews> datas) {
//            for (CommonNews info : datas) {
//            	if(info.getSlide2browser() != NewsList.TYPE_OPEN_APP)
//            		mInfos.addFirst(info);
//            }
//        }
    }
    
    /**
     * 
     * 焦点图适配器
     * 
     */
    public class BannerImageAdapter extends BaseAdapter{  
        public BannerImageAdapter(Context context) {  
        	mBannerInfos = new LinkedList<BannerNews>();
        }  
      
        @Override
    	public int getCount() {
        	return Integer.MAX_VALUE;
    	} 
      
        @Override
    	public Object getItem(int position) {
        	return null;
    	}

    	@Override
    	public long getItemId(int position) {
    		return 0;
    	} 
        
    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
    		position %= BANNER_IMAGE_LENGTH ;
    		BannerViewHolder holder;
    		BannerNews mNews = null;
    		if(position >= 0 && position < mBannerInfos.size())
    			mNews = mBannerInfos.get(position);
    		if (convertView == null) {
    			 convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.lock_item,null); //实例化convertView  
                 holder = new BannerViewHolder();
                 holder.imageView = (ImageView) convertView.findViewById(R.id.gallery_image);
                 Gallery.LayoutParams params = new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT,Gallery.LayoutParams.MATCH_PARENT);
                 convertView.setLayoutParams(params);
                 convertView.setTag(holder);
             }
             holder = (BannerViewHolder) convertView.getTag(); 
            //设置缩放比例：保持原样  
            holder.imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
            holder.imageView.setImageResource(R.drawable.banner_zw);
            if(mNews != null)
            	mImageLoader.DisplayImage(mNews.getImageUrl(), holder.imageView, false,ImageLoader.LOCK_BANNER_PICTURE); 
            return convertView;  
    	}  
    }    

    class BannerViewHolder {
        ImageView imageView;
    }
    
    /**
     * 
     * 上滑加载时资讯列表出现时的动画
     * 
     */
    private void flipUpAnim(View view,Context mContext){
    	shakeAlphaAnim = getReverseAlphaAnimation();
        shakeAnimSet = new AnimationSet(false);
        shakeAnimSet.addAnimation(shakeAlphaAnim);
        shakeAnim = AnimationUtils.loadAnimation(mContext, R.anim.shake_y);
        shakeAnimSet.addAnimation(shakeAnim);
        view.startAnimation(shakeAnimSet);
    }
    
    /**
     * 
     * 下滑加载时资讯列表的动画（已去除这部分动画，暂时未用）
     * 
     */
    private void flipDownAnim(View view,Context mContext){
    	shakeAlphaAnim = getReverseAlphaAnimation();
    	shakeAnimSet = new AnimationSet(false);
    	shakeAnimSet.addAnimation(shakeAlphaAnim);
    	shakeAnim = AnimationUtils.loadAnimation(mContext, R.anim.shake_y);
    	shakeAnimSet.addAnimation(shakeAnim);
    	view.startAnimation(shakeAnimSet);
    }
    
    private void initView(){
    	settingsView = (LinearLayout)findViewById(R.id.settings_view);
    	mMainBlurBmpIV = (ImageView)findViewById(R.id.main_blur_bg);
    	mProgressDialog = new CustomProgressDialog(this,getString(R.string.lock_loading_data));
    	lay_list_container = (RelativeLayout) findViewById(R.id.lay_list_container);
		view_load_failed = (LoadFailedView) findViewById(R.id.view_load_failed);
    	mAdapterView = (XListView) findViewById(R.id.list);
    	mAdapterView.setSelector(R.drawable.list_bg_selector);
    	LayoutInflater layoutInflator = LayoutInflater.from(this);
        lockHeaderView = layoutInflator.inflate(R.layout.lock_header_view, null);
    	mAdapterView.addHeaderView(lockHeaderView);
    	mForeBmpIV = (ImageView) findViewById(R.id.main_fore_bg);
    	mBackBmpIV = (ImageView) findViewById(R.id.main_back_bg);
    	bannerNewsTv = (TextView)lockHeaderView.findViewById(R.id.banner_news);
    	imagesGallery = (GuideGallery) lockHeaderView.findViewById(R.id.image_wall_gallery); 
    	imagesGallery.setImageActivity(this);
    	h5IconIV = (ImageView)findViewById(R.id.h5_icon);
    }
    
    private void initData(){
    	lay_list_container.setVisibility(View.VISIBLE);
    	view_load_failed.setVisibility(View.GONE);
    	mAdapterView.setPullLoadEnable(true);
    	mAdapterView.setPullRefreshEnable(false);
    	mAdapterView.setXListViewListener(this);
    	mImageLoader = ImageLoader.getInstance(this);
    	mAdapter = new StaggeredAdapter(this, mAdapterView);
    	mAdapterView.setAdapter(mAdapter);
    	bannerAdapter = new BannerImageAdapter(this);  
    	imagesGallery.setAdapter(bannerAdapter);  
    	imagesGallery.stopTimer();
    	imagesGallery.startTimer();
    	getBanner();//请求焦点图
    	readCacheData();//读取心跳缓存数据
    	//requestServerData(ON_OPEN_APP);//todo guoguaxiang 出测试包
    }
    
    /**
     * 
     * 控制H5游戏的入口可见性
     * 
     */
    private void setH5IconVisibility(){
    	MyLog.i("jyh1", "~~~~getH5GameStatus is~~~~"+SharePreferenceSdkData.getH5GameStatus(this));
    	if(!SharePreferenceSdkData.getH5GameStatus(this)){
    		h5IconIV.setVisibility(View.INVISIBLE);
    		MyLog.i("jyh1", "~~~~h5icon invisible~~~~");
    	}else{
    		h5IconIV.setVisibility(View.VISIBLE);
    		MyLog.i("jyh1", "~~~~h5icon visible~~~~");
    	}

    }
    
    private void initListener(){
    	mAdapterView.setOnTouchListener(new OnTouchListener() {
			
			@SuppressLint("NewApi") @Override
			public boolean onTouch(View v, MotionEvent event) {
				if(!isAnimating){
					switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						clickedPosition = mAdapterView.pointToPosition((int)event.getX(), (int)event.getY());
						itemView = mAdapterView.getChildAt(clickedPosition - firstItem);
						if(itemView != null && clickedPosition >= 2)
							itemDownAnimation(itemView);
						break;
					case MotionEvent.ACTION_MOVE:
						break;
					case MotionEvent.ACTION_UP:
						if(itemView != null && clickedPosition >= 2){
							itemUpAnimation(itemView);
						}
						clickedPosition = 0;
						break;
					}
				}
				return false;
			}
		});
    	
		mAdapterView.setOnScrollListener(new OnScrollListener() {
			
			@Override
			public void onScrollStateChanged(PLA_AbsListView view, int scrollState) {
				switch (scrollState) {
				case OnScrollListener.SCROLL_STATE_FLING:
					break;
				case OnScrollListener.SCROLL_STATE_IDLE:
					break;
				case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
					break;
				default:
					break;
				}
			}
				
			@Override
			public void onScroll(PLA_AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				firstItem = firstVisibleItem;
				mAdapterView.setTotalItemCount(totalItemCount);
			}
		});
    	 
    	mAdapterView.setOnItemClickListener(new OnItemClickListener() {
    		
    		@SuppressLint("NewApi") 
    		@Override
    		public void onItemClick(PLA_AdapterView<?> parent, View view,
    				int position, long id) {
    			// TODO Auto-generated method stub
    			if(!isAnimating){
    				isAnimating = true;
    				MyLog.i("jyh", "~~~~~~~~~单击编号~~~~"+position);
	    			ImageView itemImage = (ImageView) view.findViewById(R.id.news_pic);
	    			clickedView = view;
	    			clickedItemPosition = position;
	    			int curPos = clickedItemPosition - mAdapterView.getHeaderViewsCount();
	    			MainNews curNews = mInfos.get(curPos);
	    			Intent intent = new Intent();
	    			if(curNews.getEngineType() == 1){
	    				intent.putExtra("curNews", curNews);
	    				intent.putExtra("from", Constants.FROM_HOME_LIST);
	    				intent.setClass(LockMainActivity.this, GamePlayActivity.class);//首页列表中点击的如果是h5游戏，则不执行跳转动画
	    				startActivity(intent);
	    			}else{
	    				if(itemImage != null){
		    				mAdapterView.setScrollable(false);
			    			itemImage.setDrawingCacheEnabled(false);
			    			itemImage.setDrawingCacheEnabled(true);
			    			Bitmap itemBmp = itemImage.getDrawingCache();
			    			forwardingBGAnim(view, itemImage, itemBmp);
			    			forwardingFGAnim(view, itemImage, itemBmp);
		    			}
	    			}
    			}
    		}
    	});
    	
    	imagesGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
	
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				position %= BANNER_IMAGE_LENGTH;
				MyLog.i("jyh", "~~~~~~item num is~~~~~"+position);
				if(position >= 0 && position < mBannerInfos.size()){
					if(!isAnimating){
						isAnimating = true;
						imagesGallery.stopTimer();
						BannerNews mCurNews = mBannerInfos.get(position);
						UserCountHabit.setUserCount(LockMainActivity.this, UserCountHabit.BANNER_CLICK+mCurNews.getId());
						Intent intent = new Intent();
						intent.putExtra("curNews", mCurNews);
						intent.putExtra("itemPosition", position);
						intent.putExtra(Constants.FROM, "focus");
						intent.setClass(LockMainActivity.this, DetailPageActivity.class);
						startActivity(intent);
						overridePendingTransition(R.anim.enter_alpha, R.anim.leave_alpha);
					}
				}
			}
		});
    	
    	imagesGallery.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				position %= BANNER_IMAGE_LENGTH;
				MyLog.i("jyh", "~~~~~~~~~onItemSelected item position is ~~~"+position);
				if(mBannerInfos.size() > 0)
					bannerNewsTv.setText(mBannerInfos.get(position).getTitle());
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub
				
			}
		});
    	
    	settingsView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(LockMainActivity.this, SettingPageActivity.class);
				startActivityForResult(intent, 100);
				overridePendingTransition(R.anim.enter_alpha, R.anim.leave_alpha);
			}
		});
    	
    	h5IconIV.setOnClickListener(new OnClickListener() {
    		
    		@Override
    		public void onClick(View v) {
    			// TODO Auto-generated method stub
    			if(!isAnimating){
    				UserCountHabit.setUserCount(LockMainActivity.this, UserCountHabit.H5_FROM_HOME);
    				Intent intent = new Intent();
	    			intent.setClass(LockMainActivity.this, GameListActivity.class);
	    			startActivityForResult(intent, 99);
	    			overridePendingTransition(R.anim.enter_alpha, R.anim.leave_alpha);
    			}
    		}
    	});
    }
    
    /**
     * 
     * 用户点击之后的背景动画
     * 
     */
    @SuppressLint("NewApi") 
    private void forwardingBGAnim(View view,ImageView imageView,Bitmap bmp){
    	long startTime = System.currentTimeMillis();
    	bBmp = ImageUtils.fastblur(getApplicationContext(), bmp, 100);
    	MyLog.i("jyh", "blur bitmap costs ~~~~~~" + (System.currentTimeMillis() - startTime) + "~~~~~~~~~~");
    	mBackBmpIV.setImageBitmap(bBmp);
		
		float x = view.getX();
    	float y = view.getY();
    	int width = imageView.getWidth();
    	int height = imageView.getHeight();
    	x += imageView.getX();
    	y += imageView.getY();
    	bkAnimSet = new AnimationSet(true);  
    	Animation scaleAnim = scaleAnimation(mBackBmpIV,x,y,width,height);  
    	bkAnimSet.addAnimation(scaleAnim);
    	Animation translateAnim = translateAnimation(mBackBmpIV,x,y,width,height);  
    	bkAnimSet.addAnimation(translateAnim); 
    	bkAnimSet.setAnimationListener(animListener);
    	
    	bkAnimSet.setFillBefore(true);
    	bkAnimSet.setFillEnabled(true);
    	bkAnimSet.setFillAfter(true);

    	mBackBmpIV.startAnimation(bkAnimSet);
    	view.invalidate();
    }
    
    /**
     * 
     * 用户点击之后的前景动画
     * 
     */
    @SuppressLint("NewApi") 
    private void forwardingFGAnim(View view,ImageView imageView,Bitmap bmp){
    	float x = view.getX();
    	float y = view.getY();
    	MyLog.i("jyh", "~~~~view.x is ~~~"+x);
    	MyLog.i("jyh", "~~~~view.y is ~~~"+y);
    	int width = imageView.getWidth();
    	int height = imageView.getHeight();
    	x += imageView.getX();
    	y += imageView.getY();
    	itemX = x;
    	itemY = y;
    	mForeBmpIV.setImageBitmap(bmp);
    	foreAnimSet = new AnimationSet(true);  
    	Animation scaleAnim = scaleAnimation(mForeBmpIV,x,y,width,height);  
    	foreAnimSet.addAnimation(scaleAnim);
    	Animation alphaAnim = getAlphaAnimation();
    	foreAnimSet.addAnimation(alphaAnim);
    	Animation translateAnim = translateAnimation(mForeBmpIV,x,y,width,height);  
    	foreAnimSet.addAnimation(translateAnim); 
    	
    	mForeBmpIV.startAnimation(foreAnimSet);
    	view.invalidate();
    }
    
    AnimationListener animListener = new AnimationListener() {
		
		@Override
		public void onAnimationStart(Animation animation) {
			// TODO Auto-generated method stub
		}
		
		@Override
		public void onAnimationRepeat(Animation animation) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onAnimationEnd(Animation animation) {
			mAdapterView.setScrollable(true);
			int curPos = clickedItemPosition - mAdapterView.getHeaderViewsCount();
			if(curPos < 0 || curPos > mInfos.size() - 1){
				return;
			}
			MainNews curNews = mInfos.get(curPos);
			Intent intent = new Intent();
//			if(curNews.getEngineType() == 1){
//				intent.setClass(LockMainActivity.this, GamePlayActivity.class);
//				MyLog.i("jyh", "~~~~~~~~~~curNews.getEngineType() == 1~~~~~~~~~~~");
//			}else{
//				intent.setClass(LockMainActivity.this, DetailPageActivity.class);
//				MyLog.i("jyh", "~~~~~~~~~~curNews.getEngineType() != 1~~~~~~~~~~~");
//			}
			intent.putExtra("curNews", curNews);
			intent.putExtra(Constants.FROM, Constants.FROM_HOME_LIST);
			intent.setClass(LockMainActivity.this, DetailPageActivity.class);
			if(!isBack){//为防止在跳转到详情页面之前，用户点击back键，将首页activity销毁掉后使得详情页没有背景，isBack和isForwarding一起控制才能达到目的
				startActivityForResult(intent, 100);
				isForwarding = true;
				overridePendingTransition(R.anim.enter_alpha, R.anim.leave_alpha);
				h5IconIV.setVisibility(View.INVISIBLE);
				mForeBmpIV.setImageBitmap(null);//需要将前景图片置空释放掉，不然会报错
			}
			isBack = false;
			MyLog.i("jyh", "~~~~~~~~~~onAnimationEnd~~~~~~~~~~~");
		}
	};
	
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		if(arg1 == BACK_FROM_DETAIL_NOANIM){
			mBackBmpIV.clearAnimation();
			mForeBmpIV.clearAnimation();
			MyLog.i("jyh", "~~~~~BACK_FROM_DETAIL_NOANIM~~~~~~~~");
		}else if(arg1 == BACK_RROM_DETAIL_PAGE){
			mAdapterView.setScrollable(false);
			backToNormalAnim();
			MyLog.i("jyh", "~~~~~~from detail page~~~~~~~");
		}else if(arg1 == BACK_RROM_SETTING_PAGE){
			MyLog.i("jyh", "~~~~~~from setting page~~~~~~~");
			if(mainBlurBmp != null){
				mMainBlurBmpIV.setImageBitmap(mainBlurBmp);
				Animation alphaAnim = getAlphaAnimation();
				AnimationSet set = new AnimationSet(true);
				set.addAnimation(alphaAnim);
				mMainBlurBmpIV.startAnimation(set);
				mMainBlurBmpIV.setVisibility(View.INVISIBLE);
			}
		}
		MyLog.i("jyh", "~~~~~~else onActivityResult~~~~~~~");
			
	};
	
    private Animation getAlphaAnimation() {  
        //实例化 AlphaAnimation 主要是改变透明度  
        //透明度 从 1-不透明 0-完全透明   
        Animation animation = new AlphaAnimation(1.0f, 0.0f);  
        //设置动画插值器 被用来修饰动画效果,定义动画的变化率   
        animation.setInterpolator(new DecelerateInterpolator());  
        //设置动画执行时间  
        animation.setDuration(500);  
        return animation;  
    } 
    private Animation getReverseAlphaAnimation() {  
    	//实例化 AlphaAnimation 主要是改变透明度  
    	//透明度 从 1-不透明 0-完全透明   
    	Animation animation = new AlphaAnimation(0.0f, 1.0f);  
    	//设置动画插值器 被用来修饰动画效果,定义动画的变化率   
    	animation.setInterpolator(new DecelerateInterpolator());  
    	//设置动画执行时间  
    	animation.setDuration(500);  
    	return animation;  
    } 
    
    private Animation translateAnimation(View view,float x,float y,int width,int height){
    	/** 设置位移动画 向右位移150 */ 
    	int mWidth = getWidth();
    	int mHeight = getHeight() - getStatusBarHeight(LockMainActivity.this) - getTitleBarHeight();
    	MyLog.i("jyh", "mWidth/2 ~~~~~~" + mWidth/2 + "~~~~~~~~~~");
    	MyLog.i("jyh", "mHeight/2 ~~~~~~" + mHeight/2 + "~~~~~~~~~~");
    	transAni = new TranslateAnimation(x, (mWidth/2 - width/2),y, (mHeight/2  - height/2)); 
    	//设置动画插值器 被用来修饰动画效果,定义动画的变化率   
    	transAni.setInterpolator(new DecelerateInterpolator()); 
    	transAni.setDuration(500);//设置动画持续时间 
    	return transAni;
    }
    
    /**
     * 
     * 手指轻触资讯列表时的下压动画
     * 
     */
    private void itemDownAnimation(View view){
    	/** 设置缩放动画 */   
    	itemDownAnim = new ScaleAnimation(1.0f, 0.97f, 1.0f, 0.97f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);  
    	//设置动画插值器 被用来修饰动画效果,定义动画的变化率   
    	itemDownAnim.setInterpolator(new DecelerateInterpolator()); 
    	itemDownAnim.setDuration(50);//设置动画持续时间   
    	itemDownAnim.setFillEnabled(true);
    	itemDownAnim.setFillAfter(true);
    	view.startAnimation(itemDownAnim);
    }
    
    /**
     * 
     * 手指离开资讯列表时的回弹动画
     * 
     */
    private void itemUpAnimation(View view){
    	/** 设置缩放动画 */   
    	itemDownAnim.setFillEnabled(false);
    	itemDownAnim.setFillAfter(false);
    	itemUpAnim = new ScaleAnimation(0.97f, 1.0f, 0.97f,1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);  
    	itemUpAnim.setInterpolator(new DecelerateInterpolator()); 
    	itemUpAnim.setDuration(50);//设置动画持续时间
    	view.startAnimation(itemUpAnim);
    }
    
    private Animation scaleAnimation(View view,float x,float y,int width,int height){
    	/** 设置缩放动画 */   
    	int mWidth = getWidth();
    	int mHeight = getHeight() - getStatusBarHeight(LockMainActivity.this) - getTitleBarHeight();
    	scaleAni = new ScaleAnimation(1.0f, (float)mWidth/(float)width + 0.15f, 1.0f, (float)mHeight/(float)height + 0.15f, 
    			Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);  
    	widthScaleFactor = (float)mWidth/(float)width + 0.15f;
    	heightScaleFactor = (float)mHeight/(float)height + 0.15f;
    	//设置动画插值器 被用来修饰动画效果,定义动画的变化率   
    	scaleAni.setInterpolator(new DecelerateInterpolator()); 
    	scaleAni.setDuration(500);//设置动画持续时间   
    	return scaleAni;
    }
    
    /**
     * 
     * 状态栏高度
     * 
     */
    public int getStatusBarHeight(Activity activity){
    	// 获取状态栏高度 
        Rect frame = new Rect(); 
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); 
        statusBarHeight = frame.top; 
        return statusBarHeight;
    }
    
    /**
     * 
     * 标题栏高度
     * 
     */
    public int getTitleBarHeight(){
    	 int wintop = getWindow().findViewById(android.R.id.content).getTop();
         titleBarHeight = wintop - statusBarHeight;
         return titleBarHeight;
    }
    
    /**
     * 
     * 截屏
     * 
     */
    public Bitmap takeScreenShot(Activity activity) { 
        // View是你需要截图的View 
        View view = activity.getWindow().getDecorView(); 
        view.setDrawingCacheEnabled(true); 
        view.buildDrawingCache(); 
        Bitmap b1 = view.getDrawingCache(); 
  
        // 获取状态栏高度 
        Rect frame = new Rect(); 
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); 
        statusBarHeight = frame.top; 
        System.out.println(statusBarHeight); 
  
        // 获取屏幕长和高 
        int width = getWidth();
        int height = getHeight();
        // 去掉标题栏 
        // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
        int wintop = getWindow().findViewById(android.R.id.content).getTop();
        titleBarHeight = wintop - statusBarHeight;
        MyLog.i("jyh", "~~~~~statusBar height is " + statusBarHeight);
        MyLog.i("jyh", "~~~~~titleBar height is " + titleBarHeight);
        Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight + titleBarHeight, width, height - statusBarHeight - titleBarHeight); 
        view.destroyDrawingCache(); 
        return b; 
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        return true;
    }
    
    @Override
    public void onConnectChange() {
    	if(view_load_failed.getVisibility() == View.VISIBLE){
    		//请求焦点图
    		getBanner();
    		//请求首页列表数据
    		if(!checkDataCache()){
    	        if (NetHeadUtils.isNetWorking(getApplicationContext())) {
    	        	requestServerData(ON_OPEN_APP);
    	        	view_load_failed.setVisibility(View.GONE);
    			}else if(!NetHeadUtils.isNetWorking(getApplicationContext()))
    				view_load_failed.setVisibility(View.VISIBLE);
            }
    		MyLog.i("jyh1", "~~~~onConnectChange initData()~~~~");
    	}
		NetworkTask.needQuestTotalFlag(getApplicationContext());
		MyLog.i("jyh1", "~~~~lockmainactivity onConnectChange()~~~~");
    }

    @Override
    protected void onResume() {
        super.onResume();
        isForwarding = false;
        isBack = false;
        isAnimating = false;
        imagesGallery.stopTimer();
        imagesGallery.startTimer();
        setH5IconVisibility();
        MyLog.i("jyh1", "~~~~~checkdatacache~~~~~~"+checkDataCache());
        if(!checkDataCache()){//没有缓存
	        if (NetHeadUtils.isNetWorking(getApplicationContext())) {
	        	requestServerData(ON_OPEN_APP);
			}else if(!NetHeadUtils.isNetWorking(getApplicationContext()))
				view_load_failed.setVisibility(View.VISIBLE);
        }
        MyLog.i("jyh1", "~~~~~~~~mainactivity onresume~~~~~~~~~~~~");
    }
    
    /**
     * 
     * 检测首页资讯列表缓存数据是否已经存在
     * 
     */
    private boolean checkDataCache(){
    	File seriFile = new File(Constants.SERIALIZABLE_MAIN_PAGE);
		if(seriFile.exists())
			return true;
		return false;
    }
    
    @Override
    protected void onPause() {
    	// TODO Auto-generated method stub
    	super.onPause();
    	mAdapterView.stopLoadMore();
    	imagesGallery.stopTimer();
    }
    
    /**
     * 
     * 屏幕宽度
     * 
     */
    private int getWidth(){
    	DisplayMetrics dm = new DisplayMetrics();
    	getWindowManager().getDefaultDisplay().getMetrics(dm);
    	return dm.widthPixels;
    }
    
    /**
     * 
     * 屏幕高度
     * 
     */
    private int getHeight(){
    	DisplayMetrics dm = new DisplayMetrics();
    	getWindowManager().getDefaultDisplay().getMetrics(dm);
    	return dm.heightPixels;
    	
    }
    
    @SuppressLint("NewApi")
    private void backToNormalAnim(){
    	gobackForegroundAnim();
    	gobackBackgroundAnim();
    }
    
    @SuppressLint("NewApi") 
    private void gobackForegroundAnim(){
    	if(clickedView != null){
	    	ImageView itemImage = (ImageView) clickedView.findViewById(R.id.news_pic);
			itemImage.setDrawingCacheEnabled(false);
			itemImage.setDrawingCacheEnabled(true);
			Bitmap bmp = itemImage.getDrawingCache();
			mForeBmpIV.setImageBitmap(bmp);
	    	AnimationSet set = new AnimationSet(true);
	    	
	    	Animation scaleAnim = getBackScaleAnim();
	    	set.addAnimation(scaleAnim);
	    	
	    	Animation transAnim = getBackTransAnim(mForeBmpIV.getX(),mForeBmpIV.getY());
	    	set.addAnimation(transAnim);
	    	
	    	Animation alphaAnim = getBackAlphaAnim();
	    	set.addAnimation(alphaAnim);
	    	set.setAnimationListener(backAnimLisnter);
	    	mForeBmpIV.startAnimation(set);
    	}
    }
    
    @SuppressLint("NewApi") 
    private void gobackBackgroundAnim(){
    	AnimationSet set = new AnimationSet(true);
    	
    	Animation scaleAnim = getBackScaleAnim();
    	set.addAnimation(scaleAnim);
    	
    	Animation transAnim = getBackTransAnim(mBackBmpIV.getX(),mBackBmpIV.getY());
    	set.addAnimation(transAnim);
    	
    	set.setAnimationListener(backAnimLisnter);
    	mBackBmpIV.startAnimation(set);
    }
    
    
    AnimationListener backAnimLisnter = new AnimationListener() {
		
		@Override
		public void onAnimationStart(Animation animation) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onAnimationRepeat(Animation animation) {
			// TODO Auto-generated method stub
			
		}
		
		@SuppressLint("NewApi") 
		@Override
		public void onAnimationEnd(Animation animation) {
			MyLog.i("jyh", "~~~~~~~~~~onBackAnimationEnd~~~~~~~~~~~");
			mForeBmpIV.setVisibility(View.INVISIBLE);
			mBackBmpIV.setVisibility(View.INVISIBLE);
			mBackBmpIV.setImageBitmap(null);
			mForeBmpIV.setImageBitmap(null);
			mAdapterView.setScrollable(true);
			
		}
	};
	
    private Animation getBackScaleAnim(){
    	Animation mscaleAni = new ScaleAnimation(widthScaleFactor, 1.0f, heightScaleFactor, 1.0f,Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0);
    	//设置动画插值器 被用来修饰动画效果,定义动画的变化率   
    	mscaleAni.setInterpolator(new DecelerateInterpolator()); 
    	mscaleAni.setDuration(500);//设置动画持续时间   
    	return mscaleAni;
    }
    
    private Animation getBackTransAnim(float x,float y){
    	MyLog.i("jyh", "translation x and y axis is ~~~" + x + "~~" + y );
    	Animation transAni = new TranslateAnimation(x, itemX,y, itemY); 
    	//设置动画插值器 被用来修饰动画效果,定义动画的变化率   
    	transAni.setInterpolator(new DecelerateInterpolator()); 
    	transAni.setDuration(500);//设置动画持续时间 
    	return transAni;
    }
    
    private Animation getBackAlphaAnim(){
    	//实例化 AlphaAnimation 主要是改变透明度  
        //透明度 从 1-不透明 0-完全透明   
        Animation animation = new AlphaAnimation(0.0f, 1.0f);  
        //设置动画插值器 被用来修饰动画效果,定义动画的变化率   
        animation.setInterpolator(new DecelerateInterpolator());  
        //设置动画执行时间  
        animation.setDuration(500);  
        return animation;
    }
    
    private Animation getBackReverseAlphaAnim(){
    	//实例化 AlphaAnimation 主要是改变透明度  
    	//透明度 从 1-不透明 0-完全透明   
    	Animation animation = new AlphaAnimation(1.0f, 0.0f);  
    	//设置动画插值器 被用来修饰动画效果,定义动画的变化率   
    	animation.setInterpolator(new DecelerateInterpolator());  
    	//设置动画执行时间  
    	animation.setDuration(500);  
    	return animation;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyLog.i("jyh", "~~~~~~~~~~~onDestroy onDestroy ~~~~~~~~~~~");

        LockApplication.FLAG_MAIN_OPENED = false;
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	// TODO Auto-generated method stub
    	if (keyCode == KeyEvent.KEYCODE_BACK) {
    		MyLog.i("jyh", "~~~~~~~~~~~KEYCODE_BACK KEYCODE_BACK ~~~~~~~~~~~");
    		isBack = true;
    		if(!isForwarding && !isAnimating)
    			this.finish();
    		if(isAnimating && !isForwarding){
    			mBackBmpIV.clearAnimation();
    			mForeBmpIV.clearAnimation();
    			isAnimating = false;
    		}
			return true;
		}else{
			return super.onKeyDown(keyCode, event);
		}
    }

    @Override
    public void onRefresh() {
//        AddItemToContainer(++currentPage, 1);
        MyLog.i("jyh", "~~~~~~~~~~~onRefresh() is refreshing ~~~~~~~~~~~");

    }

    @Override
    public void onLoadMore() {
    	if(isRequesting){
    		return;
    	}
    	UserCountHabit.setUserCount(LockMainActivity.this, UserCountHabit.LOAD_MORE);
    	if(articleNumber < ARTICLE_MAX_NUMBER)
    		requestServerData(ON_LOAD_MORE);
    	else{
    		mAdapterView.stopLoadMore();
			Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.beyond_300_articles), Toast.LENGTH_SHORT).show();
    	}
        MyLog.i("jyh", "~~~~~~~~~~~onLoadMore() is Loading More ~~~~~~~~~~~");

    }
    
	@Override
	public String getUserHabitKey() {
		return UserCountHabit.HOME_PAGE_TIME;
	} 
	
	/**
	 * 创建小游戏快捷方式
	 */
	public void createShortCut(){   
		if(SharePreferenceSdkData.isShortCut(this)){
			return;
		}
	    //创建快捷方式的Intent                     
	    Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");                     
	    //不允许重复创建                     
	    shortcutintent.putExtra("duplicate", false);                     
	    //需要现实的名称                     
	    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_name));     
	    //快捷图片                    
	    Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_shortcut);     
	    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);     
	    //点击快捷图片，运行的程序主入口                     
	    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , GameListActivity.class));                     
	    //发送广播。OK                     
	    sendBroadcast(shortcutintent);    
	    SharePreferenceSdkData.setIsShortCut(this, true);
	}  
    
}// end of class
